package com.csg.ses.common.interceptor;

import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 * @auther wangjun
 * @date 2020/11/16
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        String msg = e.getMessage();
        if (msg == null || msg.equals("")) {
            msg = "服务器处理异常！";
        }
        if (msg.contains("401#")) {
            String[] str = msg.split("#");
            return new Result(str[1], ResultStatus.LOGIN_FAIL);
        } else {
            e.printStackTrace();
            return new Result(msg, ResultStatus.FAILED);
        }
    }
}